using System.Xml;

namespace GSN.Config
{
    public class XmlPasswordNode
    {
        private bool _encrypted = false;
        private XmlNode _node = null;

        public XmlPasswordNode(XmlNode node, bool encrypted)
        {
            _node = node;
            _encrypted = encrypted;
        }

        public XmlPasswordNode SelectSingleNode(string xpath)
        {
            XmlNode n = _node.SelectSingleNode(xpath);
            if (n == null)
                return null;

            return new XmlPasswordNode(n, _encrypted);
        }

        public string InnerText
        {
            get
            {
                return _node.InnerText;
            }
            set
            {
                _node.InnerText = value;
            }
        } 


        public string EncryptedInnerText
        {
            get
            {
                string str = _node.InnerText;
                if (_encrypted)
                    str = CryptUtils.decrypt(str);

                return str;
            }
            set
            {
                string str = value;
                if (_encrypted)
                    str = CryptUtils.encrypt(str);

                _node.InnerText = str;
            }
        } 
    }
}
